package com.cm.tianwt.socks.utils;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;


public class Configs {

	public static final int SO_TIMEOUT = 30*1000;
	
	public static final int READ_TIMEOUT = 500;
	
	public static final int IDEL_TIMEOUT = 60*60*1000; //空闲等待时间
	public static final int DEBUG_IDEL_TIMEOUT = 10*60*1000; //空闲等待时间
	
	public static final int VERSION_SOCKS_V5 = 0x05;
	
	public static final int VERSION_SOCKS_V4 = 0x04;
	
	public static final int BUFFER_DEFAULT_SIZE = 1024 * 5;

	public static final int COMMAND_BIND = 0x02;

	public static final int COMMAND_CONNECT = 0x01;
	
	public static final int COMMAND_UDP = 0x03;
	
	public static volatile boolean USE_WHITE_LIST = false;

	private static boolean NEED_AUTH_USER = false;
	
	public static final List<String> UID_WHITE_LIST = new CopyOnWriteArrayList<String>();
	
	public static final List<String> HOST_WHITE_LIST = new CopyOnWriteArrayList<String>();

	public static final int ADDRESS_IPV4 = 0x01;

	public static final int ADDRESS_IPV6 = 0x04;

	public static final int ADDRESS_DOMAIN = 0x03;
	
	public static final int ADDRESS_IPV4_LENGTH = 4;
	public static final int ADDRESS_IPV6_LENGTH = 16;

	public static final int VERSION_RCF1921 = 0x01;

	public static  boolean IS_DEBUG = false;
	
	
	public static synchronized void openWhiteList(boolean use,List<String> uids,List<String> hosts) {
		USE_WHITE_LIST = use;
		UID_WHITE_LIST.clear ();
		HOST_WHITE_LIST.clear();
		if(uids!=null){
			UID_WHITE_LIST.addAll(uids);
		}
		if(hosts!=null){
			HOST_WHITE_LIST.addAll(hosts);
		}
	}
	
	public static synchronized boolean checkWhiteList(String uid,String host) {
		return (UID_WHITE_LIST.contains(uid) ||  HOST_WHITE_LIST.contains(host));
	}
	
	public static synchronized  void setNeedAuthUserInfo(boolean auth) {
		NEED_AUTH_USER = auth;
	}
	
	public static synchronized boolean   shouldAuthUser(){
		return NEED_AUTH_USER;
	}
	
}
